package com.ruoyi.web.controller.community;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.community.domain.BbsArticleDetail;
import com.ruoyi.community.domain.HeartElderlyInfo;
import com.ruoyi.community.service.BbsArticleService;
import com.ruoyi.community.service.impl.BbsArticleServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bbs")
public class BbsArticleDetailController extends BaseController {
    @Autowired
    private BbsArticleService bbsArticleService;


    @GetMapping("/list")
    public TableDataInfo list(BbsArticleDetail bbsArticleDetail)
    {
        startPage();
        Integer communityId = SecurityUtils.getCommunityId();
        bbsArticleDetail.setCommunityid(communityId);
        List<BbsArticleDetail> list = bbsArticleService.selectBbsArticleDetailList(bbsArticleDetail);
        return getDataTable(list);
    }

    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody BbsArticleDetail bbsArticleDetail)
    {
        return  toAjax(bbsArticleService.insertSelective(bbsArticleDetail));
    }

    @GetMapping("/{articleId}")
    public BbsArticleDetail getBbsArticleById(@PathVariable Long articleId){
        return bbsArticleService.selectBbsArticleDetailById(articleId);
    }

    @PutMapping()
    public AjaxResult update(@RequestBody BbsArticleDetail bbsArticleDetail){
       return toAjax(bbsArticleService.updateByArticleId(bbsArticleDetail));
    }

    @GetMapping("/myarticle")
    public TableDataInfo myArticle(){
        startPage();
        Long userid = SecurityUtils.getUserID();
        Integer communityid = SecurityUtils.getCommunityId();
        BbsArticleDetail bbsArticleDetail = new BbsArticleDetail();
        bbsArticleDetail.setAuthorid(userid);
        bbsArticleDetail.setCommunityid(communityid);
        List<BbsArticleDetail> list = bbsArticleService.selectBbsArticleDetailList(bbsArticleDetail);
        return getDataTable(list);
    }
}
